/*
 * ServicoTarefaLocal.java
 *
 * Created on 15 de Novembro de 2007, 20:42
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.sgpa.servico;

import br.com.sgpa.dominio.Colaborador;
import br.com.sgpa.dominio.Projeto;
import br.com.sgpa.dominio.Tarefa;
import br.com.sgpa.persistencia.DaoFactory;
import br.com.sgpa.persistencia.TarefaDao;
import java.util.List;

/**
 *
 * @author Leandro
 */
public class ServicoTarefaLocal implements ServicoTarefa {
    private DaoFactory fabricaDePersistencia = new DaoFactory();
    /** Creates a new instance of ServicoTarefaLocal */
    public ServicoTarefaLocal() {
    }
    
    public void criarTarefa(Tarefa tarefa){
        fabricaDePersistencia.beginTransaction();
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao();
        tarefaDao.inserir(tarefa);
        fabricaDePersistencia.commit();
    }
    
    public List<Tarefa> listarTarefas(Projeto proj){
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao() ;
        return tarefaDao.listarTarefas(proj);
    }
    
    public void salvarTarefa(Tarefa tarefa){
        fabricaDePersistencia.beginTransaction();
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao();
        tarefaDao.alterar(tarefa);
        fabricaDePersistencia.commit();
    }
    
    public void desativarTarefa(Tarefa tarefa){
        fabricaDePersistencia.beginTransaction();
        tarefa.desativar();
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao();
        tarefaDao.alterar(tarefa);
        fabricaDePersistencia.commit();
    }
    
    public List<Tarefa> listarTarefas(Colaborador executor){
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao() ;
        return tarefaDao.listarTarefasAExecutar(executor);
    }
    public Tarefa carregarTarefa(Tarefa tarefa){
        TarefaDao tarefaDao;
        tarefaDao = fabricaDePersistencia.criarTarefaDao() ;
        return tarefaDao.consultarPorId(tarefa.getId());
    }
    
}
